using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;

namespace Dida
{
	public class ImmutableCollection<T> : ICollection<T>
	{
		private ICollection<T> wrapped;

		public ImmutableCollection(ICollection<T> wrapThis)
		{
			wrapped = wrapThis;
		}

		#region ICollection<T> Members

		public void Add(T item)
		{
			Debug.Fail("You can't add items to this collection, since it's an ImmutableCollection");
		}

		public void Clear()
		{
			Debug.Fail("You can't clear this collection, since it's an ImmutableCollection");
		}

		public bool Contains(T item)
		{
			return wrapped.Contains(item);
		}

		public void CopyTo(T[] array, int arrayIndex)
		{
			wrapped.CopyTo(array, arrayIndex);
		}

		public int Count
		{
			get
			{
				return wrapped.Count;
			}
		}

		public bool IsReadOnly
		{
			get { return wrapped.IsReadOnly; }
		}

		public bool Remove(T item)
		{
			Debug.Fail("You can't remove an item from this collection, since it's an ImmutableCollection");
			return false;
		}

		#endregion

		#region IEnumerable<T> Members

		public IEnumerator<T> GetEnumerator()
		{
			return wrapped.GetEnumerator();
		}

		#endregion

		#region IEnumerable Members

		IEnumerator IEnumerable.GetEnumerator()
		{
			return wrapped.GetEnumerator();
		}

		#endregion
	}

	public class ImmutableList<T> : IList<T>
	{
		IList<T> wrapped;

		public ImmutableList(IList<T> wrapThis)
		{
			wrapped = wrapThis;
		}

		#region IList<T> Members

		public int IndexOf(T item)
		{
			return wrapped.IndexOf(item);
		}

		public void Insert(int index, T item)
		{
			Debug.Fail("You can't Insert items into this list, since it's an ImmutableList");
		}

		public void RemoveAt(int index)
		{
			Debug.Fail("You can't remove items from this list, since it's an ImmutableList");
		}

		public T this[int index]
		{
			get
			{
				return wrapped[index];
			}

			set
			{
				Debug.Fail("You can't set items of this list, since it's an ImmutableList");
			}
		}

		#endregion

		#region ICollection<T> Members

		public void Add(T item)
		{
			Debug.Fail("You can't add items to this list, since it's an ImmutableList");
		}

		public void Clear()
		{
			Debug.Fail("You can't clear sthis list, since it's an ImmutableList");
		}

		public bool Contains(T item)
		{
			return wrapped.Contains(item);
		}

		public void CopyTo(T[] array, int arrayIndex)
		{
			wrapped.CopyTo(array, arrayIndex);
		}

		public int Count
		{
			get { return wrapped.Count; }
		}

		public bool IsReadOnly
		{
			get { return true; }
		}

		public bool Remove(T item)
		{
			Debug.Fail("You can't remove items from this list, since it's an ImmutableList");
			return false;
		}

		#endregion

		#region IEnumerable<T> Members

		public IEnumerator<T> GetEnumerator()
		{
			return wrapped.GetEnumerator();
		}

		#endregion

		#region IEnumerable Members

		IEnumerator IEnumerable.GetEnumerator()
		{
			return wrapped.GetEnumerator();
		}

		#endregion
	}
}